/**
 * Copyright(C) 2008 Matthias Braunhofer
 * All rights reserved
 *
 * Created on: 04.09.2008
 */

package it.cums.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Converter {
	
	public static boolean isInteger(String string) {
		try {
			convertToInteger(string);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public static int convertToInteger(String string) throws NumberFormatException {
		return Integer.parseInt(string);
	}
	
	public static boolean isDouble(String string) {
		try {
			convertToDouble(string);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public static double convertToDouble(String string) throws NumberFormatException {
		return Double.parseDouble(string);
	}
	
	public static boolean isDate(String string) {
		try {
			convertToDate(string);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public static Date convertToDate(String string) throws ParseException{
		if (string.equals("")) {
			return null;
		} else {
			SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
			return format.parse(string);
		}
	}
	
	public static String convertToString(Date date) {
		if (date == null) {
			return "";
		} else {
			SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
			return format.format(date);
		}
	}
}
